// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   TagRepositoryJdbc.java

package dale.web.tag.repository;

import java.util.List;

import javax.sql.DataSource;

import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
import org.springframework.jdbc.core.simple.SimpleJdbcInsert;

import dale.web.tag.domain.Tag;

// Referenced classes of package dale.web.tag.repository:
//            TagRepository

public class TagRepositoryJdbc
    implements TagRepository
{

    public TagRepositoryJdbc(DataSource dataSource)
    {
        template = new NamedParameterJdbcTemplate(dataSource);
        insert = new SimpleJdbcInsert(dataSource);
        insert.withTableName("tag");
        mapper = new BeanPropertyRowMapper();
    }

    public List list(Tag tag)
    {
        String sql = "SELECT * FROM tag\n";
        SqlParameterSource param = tag == null ? null : ((SqlParameterSource) (new BeanPropertySqlParameterSource(tag)));
        return template.query(sql, param, mapper);
    }

    public void insert(Tag tag)
    {
        SqlParameterSource param = new BeanPropertySqlParameterSource(tag);
        int count = insert.execute(param);
        if(count != 1)
            throw new RuntimeException("No rows were inserted.");
        else
            return;
    }

    public void delete(String tagID)
    {
        String sql = "DELETE FROM tag\nWHERE tagID = :tagID\n";
        MapSqlParameterSource param = new MapSqlParameterSource();
        param.addValue("tagID", tagID);
        int count = template.update(sql, param);
        if(count != 1)
            throw new RuntimeException("No rows were deleted.");
        else
            return;
    }

/*    public transient int in(String tagIDs[])
    {
        String sql = "SELECT COUNT(tagID) FROM tag WHERE tagID IN (";
        for(int i = 0; i < tagIDs.length - 1; i++)
            sql = (new StringBuilder(String.valueOf(sql))).append(tagIDs[i]).append(",").toString();

        return 0;
    }*/

    private static final String SELECT = "SELECT * FROM tag\n";
    private static final String WHERE = "WHERE tagID = :tagID\n";
    private NamedParameterJdbcTemplate template;
    private SimpleJdbcInsert insert;
    private RowMapper mapper;
}
